﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sustainalytics.Synchronization.Interface;

namespace Sustainalytics.Universes.Synchronization.Tests
{
    using Xunit;

    public class CompanyUniversesSynchronizationTests
    {
        [Fact]
        public void UniversesFromCrmSyncStep()
        {
            var step = new UniversesFromCrmSyncStep();
            var resultContext = step.Start(GetSyncContext());
            Assert.True(resultContext.Status == SyncOperationStatus.Succeeded);
        }

        [Fact]
        public void UniversesFromExcel()
        {
            var step = new LoadFeatureUniversesSyncStep();
            var resultContext = step.Start(GetSyncContext());
            Assert.True(resultContext.Status == SyncOperationStatus.Succeeded);
        }

        private SyncContext GetSyncContext()
        {
            // set up 
            var context = new SyncContext(ErrorPolicy.BreakRightAway);
            context.Report = new ConcurrentBag<string>();
            context.IsInitialSync = true;
            context.Status = SyncOperationStatus.Failed;
            context.Token = new CancellationToken();
            context.GAConnectionStrings = new Dictionary<string, string>();
            context.CompanyUniverses = new Dictionary<Guid, List<int>>();

            // set up db
            context.GAConnectionStrings["ClientPlatform"] = "mongodb://localhost:27017/ClientPlatform";
            context.GAConnectionStrings["ClientDW"] = "mongodb://localhost:27017/ClientDW_A";
            context.GAConnectionStrings["CompanySearchDW"] = "mongodb://localhost:27017/CompanySearchDW_A";
            context.GAConnectionStrings["ClientUniverses"] = "mongodb://localhost:27017/ClientUniverses_A";
            context.GAConnectionStrings["CRM"] = "Url=https://sustainalytics0.crm4.dynamics.com;Username=client.platform@sustainalytics.com;Password=M46iaHerm3s21!";

            return context;
        }
    }
}
